import { addEmpAPI, deleteEmpAPI, editEmpAPI, fetchEmpAPI, fetchEmpDetailAPI } from '@/api/empApi'

const actions = {
  async fetchEmpAction(context, params) {
    const { data } = await fetchEmpAPI(params)
    context.commit('setEmpMutation', data)
  },

  async deleteEmpAction(context, ids) {
    const { data } = await deleteEmpAPI(ids)
    return data
  },
  async addEmpAction(context, empInfo) {
    const { data } = await addEmpAPI(empInfo)
    return data
  },
  async fetchEmpDetailAction(context, id) {
    const { data } = await fetchEmpDetailAPI(id)
    return data
  },
  async editEmpAction(context, empInfo) {
    const { data } = await editEmpAPI(empInfo)
    return data
  }
}

const mutations = {
  setEmpMutation(state, { rows, total }) {
    state.empList = rows
    state.total = total
  }
}

const state = () => {
  return {
    empList: [],
    total: 0
  }
}

const getters = {}

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true
}
